import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import javadsd from '@dfeidao/atom-web/msg/javadsd';
import nodejs from '@dfeidao/atom-web/msg/nodejs';

import tree from '@dfeidao/fd-w000001';
interface B {
	docDataStore: {
		master: {
			dataArray: [{
				client_type: string
				productid: string;
				formid: string;
				formname: string;
				level_no: string;
				group_number: string;
			}]
		};
	};
}
export default async function a017(fd: IFeidaoAiBrowserComponent, args: { level: string }) {
	const productid1 = get(fd, 'productid');

	const select = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select.options.selectedIndex;
	const client_type1 = select.options[index].value;
	const condition = {
		param: {
			productid: productid1,
			client_type: client_type1,
			level_no: args.level

		}
	};
	const ret = await javadsd('12', '12', 'smart_securitydsd0000011', condition) as B;
	// debugger;
	const array = new Array();

	ret.docDataStore.master.dataArray.forEach((i) => {
		array.push(i.formid);
	});

	const zds = fd.data.node.querySelector('[zds]') as tree;
	zds.uncheck_all();
	// console.log(array1);
	zds.check_node(array);

	const res1 = await nodejs<{ dataArray: Array<{ action_name: string, formid: string, action_keyword: string, code: string, _id: string, productid: string }> }>('level-inf/zj-000001/s011', { filter: { productid: productid1, formid_arr: array } });//
	const a = new Map();
	// console.log(res1);
	res1.dataArray.forEach((i) => {
		if (Array.from(a.keys()).indexOf(i.formid) === -1) {
			a.set(i.formid, {
				left: {},
				right: [i]
			});
		} else {
			const te = a.get(i.formid);
			te.right.push(i);
		}
	});
	// console.log(array1);“formid功能号”formname功能名称“ client_type客户端” =  "productid产品ID" = 当前登陆人的“productid”、 "level_no

	ret.docDataStore.master.dataArray.forEach((item) => {
		if (Array.from(a.keys()).indexOf(item.formid) === -1) {
			a.set(item.formid, {
				left: { client_type: item.client_type, formid: item.formid, formname: item.formname, productid: productid1, level_no: item.level_no },
				right: []
			});
		} else {
			const te = a.get(item.formid);
			te.left = { client_type: item.client_type, formid: item.formid, formname: item.formname, productid: productid1, level_no: item.level_no };
		}

	});
	// debugger;
	// console.log(a);
	set(fd, 'origin_obj', a);
}
